2020-2021 Sunseeker Telemetry and Lighting System
usci_a_uart_ex1_loopbackAdvance.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
56 //******************************************************************************
57 #include "driverlib.h"
58 
59 //*****************************************************************************
60 //
61 //Select Baud rate
62 //
63 //*****************************************************************************
64 #define BAUD_RATE 9600
65 //*****************************************************************************
66 //
67 //Initialize received data
68 //
69 //*****************************************************************************
70 uint8_t receivedData = 0x00;
71 //*****************************************************************************
72 //
73 //Initialize trasnmit data
74 //
75 //*****************************************************************************
76 uint8_t transmitData = 0x00;
77 
78 uint8_t check = 0;
79 
80 void main (void)
81 {
82  //Stop WDT
83  WDT_A_hold(WDT_A_BASE);
84 
85  //P3.4,5 = USCI_A0 TXD/RXD
86  GPIO_setAsPeripheralModuleFunctionInputPin(
87  GPIO_PORT_P3,
88  GPIO_PIN4 + GPIO_PIN5
89  );
90 
91  //Baudrate = 9600, clock freq = 1.048MHz
92  //UCBRx = 109, UCBRFx = 0, UCBRSx = 2, UCOS16 = 0
93  USCI_A_UART_initParam param = {0};
94  param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
95  param.clockPrescalar = 109;
96  param.firstModReg = 0;
97  param.secondModReg = 2;
98  param.parity = USCI_A_UART_NO_PARITY;
99  param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
100  param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
101  param.uartMode = USCI_A_UART_MODE;
102  param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
103 
104  if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
105  return;
106  }
107 
108  //Enable UART module for operation
109  USCI_A_UART_enable(USCI_A0_BASE);
110 
111  //Enable Receive Interrupt
112  USCI_A_UART_clearInterrupt(USCI_A0_BASE,
113  USCI_A_UART_RECEIVE_INTERRUPT);
114  USCI_A_UART_enableInterrupt(USCI_A0_BASE,
115  USCI_A_UART_RECEIVE_INTERRUPT);
116 
117  __enable_interrupt();
118 
119  while (1)
120  {
121  transmitData = transmitData+1; // Increment TX data
122  // Load data onto buffer
123  USCI_A_UART_transmitData(USCI_A0_BASE,
124  transmitData);
125  while(check != 1);
126  check = 0;
127  }
128 }
129 
130 //******************************************************************************
131 //
132 //This is the USCI_A0 interrupt vector service routine.
133 //
134 //******************************************************************************
135 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
136 #pragma vector=USCI_A0_VECTOR
137 __interrupt
138 #elif defined(__GNUC__)
139 __attribute__((interrupt(USCI_A0_VECTOR)))
140 #endif
141 void USCI_A0_ISR (void)
142 {
143  switch (__even_in_range(UCA0IV,4)){
144  //Vector 2 - RXIFG
145  case 2:
146  receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
147  if(!(receivedData == transmitData)) // Check value
148  {
149  while(1);
150  }
151  check =1;
152  break;
153  default: break;
154  }
155 }
156 
MPU_initThreeSegmentsParam param
#define STATUS_FAIL
Definition: hw_memmap.h:23
uint8_t receivedData
void main(void)
void USCI_A0_ISR(void)
uint8_t transmitData